<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title><?php echo ($webData["title"]); ?></title>
		<link rel="shortcut icon" href=" __PUBLIC__/Imgs/bitbug_favicon.ico" />
		<link href="__PUBLIC__/Home/Css/header.css" rel="stylesheet" type="text/css" />	
	</head>
	<body>
		<div id="header_top">
<!--			<img src="__ROOT__/Uploads/thumb/th_<?php echo ($webData["logo"]); ?>" style="float:left;" width="150">-->
			<img src="__ROOT__/Uploads/thumb/st.jpg" style="float:left;" width="150">
			<form action="__APP__/Index/searchFoods" method="post">
				<input type="text" id="header_seach" name="fname">
				<input type="submit" id="header_sub" value="搜索">
			</form>

			<ul id="header_ul">
				<li><a href="__APP__/Index/index/">首页</a></li>
				<li><a href="__APP__/Bclass/index/">菜谱分类</a></li>
			</ul>
			<div id="header_login">
			<?php if(empty($_SESSION['uname'])): ?><span>
						<a href="__APP__/Login/login/" target="_blank">
							登录
						</a>
					</span>
					<span>
						<a href="__APP__/Login/reg/" target="_blank">
							注册
						</a>
					</span>
			<?php else: ?>				
				<span>
					<a href="">
					<?php echo (session('uname')); ?>
					</a>
				</span>
				<span>
					<a href="__APP__/Ucenter/index/pass">
					个人中心
					</a>
				</span>
				<span>
					<a href="__APP__/Carts/showCarts/">
					购物车
					</a>
				</span>
				<?php if(!empty($_SESSION['uMsg'])): ?><span>
					<a href="__APP__/Posts/details/form_number/<?php echo (session('uMsg')); ?>" class="clearMsg">
					新订单
					</a>
				</span><?php endif; ?>
				<span style="font-size:14px;">
					<a href="__APP__/Public/loginout/">
					退出
					</a>
				</span><?php endif; ?>
			</div>
		</div>
		<div style="clear:both;height:30px;"></div>
	</body>
</html>
<head>
    <meta charset="UTF-8">
    <title>购物车</title>
    <link rel="stylesheet" href="__PUBLIC__/Home/Css/carts.css">
    <script type="text/javascript" src="__PUBLIC__/Js/jquery-1.8.3.js"></script>
</head>
<script>
    $(function(){
        setPrice();     //设置价格

        $("#carts .carts_center .tr_hui").mouseover(function(){
            $(this).css({background:'#f2f2f2'});
        });
        $("#carts .carts_center .tr_hui").mouseout(function(){
            $(this).css({background:'white'});
        })

        //回首页
        $('#toIndex').click(function(){

            window.location.href="__APP__/Index/index/";
        });

        $('.in').click(function(){
            setPrice();     //设置价格
        });

        $('.all').click(function(){

            var obj = document.getElementsByName('input[]');
            //兼容写法
            var n=obj.length;

            for(var i=0;i<n;i++){
                if(obj[i].checked){
                    obj[i].checked=false;
                }else{
                    obj[i].checked=true;
                }
            }

            setPrice();     //设置价格
        });

        $('.delCarts').click(function(){

            if(!confirm('你确定要删除吗?')){
                return false;
            }

            var $th = $(this);
            // var id = $(this).parent().siblings().children('.in').val();
            var id = $(this).attr('alt');
            var url = '__APP__/Carts/delCarts/';

            id = parseInt(id);

            $.post(url,{id:id},function(data){

                if('YES' == data.data){
                    $th.parent().parent().remove();
                    setPrice();     //设置价格
                }else{
                    alert('删除失败!');
                }
            });
        });

        $('.delSome').click(function(){
            if(!confirm('你确定要删除吗?')){
                return false;
            }

            var checked = $('.in:checked');
            var n=checked.length;

            for(var i=0; i<n; i++){
                var url = '__APP__/Carts/delCarts/';
                $.post(url,{id:$(checked[i]).siblings('input:hidden').val()},function(data){

                    if('YES' == data.data){
                        $('.in:checked').parent().parent().remove();
                        setPrice();     //设置价格
                    }
                });
            }


        });

        $('.input_text').blur(function(){
            $pat  = /^[1-9]\d*|0$/;
            if(!$pat.test($(this).val())){
                alert('这不是一个合法的值');
                $(this).val(1);
            }

            var yp = $(this).attr('id');
            var ypr = $('.'+yp).text();
            // setPrice();     //设置价格
            $(this).parent().siblings('.oneTatal').text($(this).val()*ypr);
            setPrice();
        });

        $('#addForms').submit(function(){
            var checked = $('.in:checked');
            var n=checked.length;
            if(n<1){
                alert('您还没有选择美食！');
                return false;
            }
        });

        /* 计算支付总额 */
        function setPrice(){
            var obj = $('.in:checked');
            var id;
            var price = 0;
            var number = 0;
            var sum = 0;
            var total = 0;

            for(var i=0; i<obj.length; i++){
                id = $(obj[i]).val();
                price = parseInt($('.'+id).text());
                number = parseInt($('#'+id).val());
                total = price*number;
                $(obj[i]).parent().siblings('.oneTatal').text(total);
                //设置单类美食总计
                sum += total;
            }

            $('#sumMoney').text(sum+'元');
        }

    });
</script>
<body>
<div id="carts">
    <div class="carts_top">　我的购物车</div>
    <div class="carts_center">
        <form action="__APP__/Posts/addPosts/" method="post" id="addForms">
            <table width="940" border="0" cellspacing="0" cellpadding="0" align="center">
                <tr class="carts_center_th">
                    <th width="25"><input type="checkbox" class="all"></th>
                    <th width="44">全选</th>
                    <th colspan="2">美食名称</th>
                    <th colspan="2">原价（元）</th>
                    <th colspan="2">单价（元）</th>
                    <th colspan="2">数量</th>
                    <th colspan="2">小计(元)</th>
                    <th colspan="2">操作</th>
                </tr>
                <?php if(is_array($_SESSION['carts'])): $i = 0; $__LIST__ = $_SESSION['carts'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr class="tr_hui">
                        <td height="46"></td>
                        <td>
                            <input type="checkbox" class="in" name="input[]" value="<?php echo ($vo["fid"]); ?>">
                            <input type="hidden" value="<?php echo ($vo["id"]); ?>">
                        </td>
                        <td width="40">&nbsp;</td>
                        <td class="carts_center_left" width="145">
                            <?php echo ($vo["name"]); ?>
                        </td>
                        <td width="65">&nbsp;</td>
                        <td class="carts_center_left" width="91">
                            <?php echo ($vo["price"]); ?>
                        </td>
                        <td width="62">&nbsp;</td>
                        <td class="carts_center_left" width="87" >
                            <font class="<?php echo ($vo["fid"]); ?>">
                                <?php if(($vo['yprice'] == $vo['price']) or ($vo['yprice'] == '')): echo ($vo['price']); ?>
                                    <?php else: ?>
                                    <?php echo ($vo['yprice']); endif; ?>
                            </font>
                        </td>
                        <td width="30">&nbsp;</td>
                        <td class="carts_center_left" width="82">
                            <input class="input_text" id="<?php echo ($vo["fid"]); ?>" type="text" name="number[<?php echo ($vo['fid']); ?>]"  value="<?php echo ($vo['number']); ?>">
                        </td>
                        <td width="52">&nbsp;</td>
                        <td class="carts_center_left carts_red oneTatal" width="81"><?php echo ($vo['total']); ?></td>
                        <td width="35">&nbsp;</td>
                        <td class="carts_center_left" width="66">
                            <a class="delCarts" alt="<?php echo ($vo["id"]); ?>">删除</a>
                        </td>
                    </tr><?php endforeach; endif; else: echo "" ;endif; ?>

                <tr class="carts_center_th carts_two">
                    <!--                                            <th height="50" width="25"><input type="checkbox" class="all"></th>-->
                    <!--                                            <th width="44">全选</th>-->
                    <!--                                            <th colspan="2" align="left"><a class="delSome">批量删除</a></th>-->
                    <th colspan="2">&nbsp;</th>
                    <th colspan="2">&nbsp;</th>
                    <td class="carts_total" colspan="9">您共需支付：</td>
                    <td class="carts_tv carts_red" colspan="3" id="sumMoney">

                    </td>
                </tr>
                <tr class="carts_center_th carts_two">
                    <td height="50" width="25">&nbsp;</td>
                    <td width="44">&nbsp;</td>
                    <td colspan="2">&nbsp;</td>
                    <td colspan="2">&nbsp;</td>
                    <td colspan="2">&nbsp;</td>
                    <td colspan="6">
                        　　　　　　　　　　<input class="inp28" type="button" id="toIndex" value="继续购买">　　　
                        <input class="inp28" type="submit" id="createForms" value="提交订单">
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>